package com.bright.hxj.qchz.util;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonUtil {


    public static List<Map<String, Object>> changeMapKeysToLowerCase(List<Map<String, Object>> lists) {
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (Map<String, Object> list : lists) {
            Map<String, Object> map = new HashMap<>();
            for (Map.Entry<String, Object> entry : list.entrySet()) {
                map.put(entry.getKey().toLowerCase(), entry.getValue());
            }
            dataList.add(map);
        }
        return dataList;
    }


    public static List<Map<String, String>> changeMapValuesToString(JSONArray dataArray) {
        List<Map<String, String>> result = new ArrayList<>();
        for (int i = 0; i < dataArray.length(); i++) {
            Map<String, String> map = new HashMap<>();
            JSONObject jsonObject = dataArray.getJSONObject(i);
            for (String key : jsonObject.keySet()) {
                map.put(String.valueOf(key), String.valueOf(jsonObject.get(key)));
            }
            result.add(map);
        }
        return result;
    }
}
